$(function(){	
	spreadSpeedInfo();
	getAllCheckPointConfig();
});	

/**
 * 获取报表下所有已配置的规则信息
 */
function getAllCheckPointConfig(){
	$.ajax({
		url:ctx+'/urgentrptmgr/speedReportAction!getRuleByReportId.action',
		data:{reportId:$('#reportid').val(),reportType:$("#reporttype").val()},
		dataType:'json',
		success:function(data){						
			createGZInfo(data);//构造时间轴				
		}
	});
}

//收缩按钮事件
function spreadSpeedInfo()
{
	$("#addDiv").slideUp("slow"); //关闭添加急报快报文本框
	$("#speedreportInfoDiv").slideDown("slow"); //展开急报快报信息
	$("#showGZDiv").css("height", "480px");
}

//展开按钮事件
function spreadSpeedReportInfo()
{
	$("#addDiv").slideDown("slow"); //关闭添加急报快报文本框
	$("#speedreportInfoDiv").slideUp("slow"); 
	$("#showGZDiv").css("height", "303px");
}

//st:对象  type:class名称  change:改变小图标的名称
function cbart (st,type,change) 
{ 
	document.getElementById(st).className = type;
	if(change!=""&&change!=null&&change!=undefined)
	{
		$("#"+st).children().children().attr("src",ctx+"/images/speedreport/"+change);
	}
} 
function sbart (st,type,change)
{ 
	document.getElementById(st).className = type;
	if(change!=""&&change!=null&&change!=undefined)
	{
		$("#"+st).children().children().attr("src",ctx+"/images/speedreport/"+change);
	}
}

//规则信息
function createGZInfo(data)
{
	var allLifeInfoHTML="";
	
	allLifeInfoHTML +='<div class="head-warp" style="padding-top:10px;*border-bottom:1px dashed #40A5D7;height:0px">   ';                                          
	allLifeInfoHTML +='  <div class="head">       ';                                                                                                               
	allLifeInfoHTML +='        <div class="nav-box" >     ';                                                                                                       
	allLifeInfoHTML +='          <ul>     ';                                                                                                                       
	allLifeInfoHTML +='              <li class="cur" style="text-align:left;padding-top:7px;padding-left:17px;font-size:30px;" ></li>';
	allLifeInfoHTML +='          </ul>     ';                                                                                                                      
	allLifeInfoHTML +='        </div>     ';                                                                                                                       
	allLifeInfoHTML +='  </div>      ';                                                                                                                            
	allLifeInfoHTML +='</div>      ';      
	allLifeInfoHTML +=' <div class="main" style="padding-left:12px;padding-top:20px">';
	allLifeInfoHTML +='  <div class="history" id="history">';
	allLifeInfoHTML +=' <div class="history-date">';
	allLifeInfoHTML +='  <ul>';
	allLifeInfoHTML +='	<div class="first"><a href="#nogo"></a></div>';
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </br>"; 
	
	if(data != null)
	{
		for(var i=0;i<data.length;i++)
		{
			allLifeInfoHTML +='<li class="green">';
			allLifeInfoHTML +='<h3><span>'+data[i].checkTime+getCheckTimeUnit()+'</span></h3>';
			allLifeInfoHTML +='<dl>';
			allLifeInfoHTML +='<dt>';
			
			allLifeInfoHTML +='<table class="showGZ" border="0">';
			allLifeInfoHTML +='<tr>';
			allLifeInfoHTML +='<td width="65px" height="44px">';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td align="left"><span class="showGZ-text1" style="color: #4f8fc7;font-size: 14px;" title="'+data[i].chekcRuleName+'">'+data[i].chekcRuleName+'</span>';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td align="right">';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='</tr>';
			
			allLifeInfoHTML +='<tr>';
			allLifeInfoHTML +='<td>';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td align="left">规则算法：'+data[i].ruleAlgorithmName;
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td align="left">告警级别：';
			allLifeInfoHTML +='<em class="'+warnLevelColor(data[i].warnLevel)+'" >'+data[i].warnLevelName+'</em>';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='</tr>';
			
			allLifeInfoHTML +='<tr>';
			allLifeInfoHTML +='<td>';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td colspan="2" align="left">阀值上限：'+data[i].thresholdMax;
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='</tr>';
			
			allLifeInfoHTML +='<tr>';
			allLifeInfoHTML +='<td>';
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='<td colspan="2" align="left">阀值下限：'+data[i].thresholdMin;
			allLifeInfoHTML +='</td>';
			allLifeInfoHTML +='</tr>';
			
			allLifeInfoHTML +='</table>';
			allLifeInfoHTML +='</dt>';
			allLifeInfoHTML +='</dl>';
			allLifeInfoHTML +='</li>';
	   
		}
	}
	
	allLifeInfoHTML +="	  </ul>"; 
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </br>"; 
	allLifeInfoHTML +="	  </div>"; 
	allLifeInfoHTML +="	  </div>"; 
	allLifeInfoHTML +="	  </div>"; 
	$("#showGZDiv").html(allLifeInfoHTML);
}

/**
 * 根据告警级别，告警内容显示相应的颜色
 * @param warnLevel
 */
function warnLevelColor(warnLevel)
{
	var className = "";
	
	//严重告警
	if (warnLevel == 3)
	{
		className = "warn_serious";
	}
	
	//重要告警
	else if (warnLevel == 2)
	{
		className = "warn_important";
	}
	
	//一般告警
	else if (warnLevel == 1)
	{
		className = "warn_common";
	}
	
	//正常
	else
	{
		className = "warn_normal";
	}
	
	return className;
}

/**
 * 根据周期类型获取时间点的单位信息
 * 月：单位是日
 * 日：单位是点
 */
function getCheckTimeUnit()
{
	var periodType = $("#periodType").val();
	var unitName = "";
	//周期类型为月
	if(periodType == '2'){
		unitName = "日";
	}
	
	else if(periodType == '3'){
		unitName = "点";
	}
	
	return unitName;
}
